package com.tool.engine.export.factory.thread;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

public class ExportTaskThreadFactory implements ThreadFactory{
    private final AtomicInteger threadNumber = new AtomicInteger(1);
    private final String namePrefix;

    public ExportTaskThreadFactory(String prefix) {
        namePrefix = prefix;
    }
    public Thread newThread(Runnable r) {
        Thread t = new Thread(null, r,
                namePrefix + threadNumber.getAndIncrement(),
                0);
        if (t.isDaemon())
            t.setDaemon(false);
        if (t.getPriority() != Thread.NORM_PRIORITY)
            t.setPriority(Thread.NORM_PRIORITY);
        return t;
    }

}
